<%@ page language="java" import="java.util.*,com.ncp.model.biz.news.*,com.ncp.model.entity.news.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int pageSize=10;//一页显示几条记录
int pageNow=1;//希望显示的页面
int linkNum=5;//表示出现的链接数
//动态接收pageNow
String pagenow=request.getParameter("pageNow");
if(pagenow!=null){
	pageNow=Integer.parseInt(pagenow);	
}
NewsManager nm=new NewsManager();
ArrayList al=nm.fenYe(pageSize,pageNow);
int pageCount=nm.getPageCount();
//System.out.println("pageCount:"+pageCount);
//System.out.println("pageNow:"+pageNow);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
  </head>
  
  <body><center>
  <table border="1" align="center">
    	<tr>
    		<td>题目</td>
       		<td>处理</td>
    	</tr>
    	<%
    		for(int i=0;i<al.size();i++){
    			NewsBean nb=(NewsBean)al.get(i);
    	 %>
    	 <tr>
    		<td><%=nb.getTitle() %></td>
    		<td><a href="NewsClServlet?type=del&id=<%=nb.getId()%>">删除</a></td>
    	 </tr>
    	 <%
    	 }
    	  %>
    </table>
    <% 
		if(pageNow>1){
			%>
			<a href="NewsClServlet?type=fenye&pageNow=1">首页</a>
			<a href="NewsClServlet?type=fenye&pageNow=<%=pageNow-1 %>">上一页</a>
			<% 
		}
		if(pageNow==2||pageNow==3){
			for(int i=1;i<=linkNum;i++){
				if(i==pageNow){
					out.println(i+"");
				}else if(i<=pageCount){
					out.println("<a href=NewsClServlet?type=fenye&pageNow="+i+">["+i+"]</a>");
				}
			}
		}else if(pageNow>3&&pageNow<(pageCount-2)){
			for(int i=pageNow-2;i<=pageNow+2;i++){
				if(i==pageNow){
					out.println(i+"");
				}else{
					out.println("<a href=NewsClServlet?type=fenye&pageNow="+i+">["+i+"]</a>");
				}
			}
		}else if(pageNow<=pageCount){
			for(int i=pageCount-linkNum+1;i<=pageCount;i++){
				if(i==pageNow){
					out.println(i+"");
				}else if(i>0){
					out.println("<a href=NewsClServlet?type=fenye&pageNow="+i+">["+i+"]</a>");
				}
			}
		}
		if(pageNow<pageCount){
			out.println("<a href=NewsClServlet?type=fenye&pageNow="+(pageNow+1)+">下一页</a>");
			out.println("<a href=NewsClServlet?type=fenye&pageNow="+pageCount+">尾页</a>");
		}
   %>
  </center></body>
</html>
